package com.atguigu.mr.order;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * @description: xxx
 * @time: 20191228 22:24
 * @author: baojinlong
 **/
public class OrderGroupingComparator extends WritableComparator {
    /**
     * 必须写上构造
     */
    public OrderGroupingComparator() {
        super(OrderBean.class, true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        // 只要id相同就认为是相同的key
        OrderBean aOrderBean = (OrderBean) a;
        OrderBean bOrderBean = (OrderBean) b;
        int result = 0;
        if (aOrderBean.getOrderId() > bOrderBean.getOrderId()) {
            result = 1;
        } else if (aOrderBean.getOrderId() < bOrderBean.getOrderId()) {
            result = -1;
        }
        // id相同的就作为同一个key
        return result;
    }
}
